package us.gaaoc.framework.signature.visual.controllers;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import javax.faces.context.FacesContext;

import com.lowagie.text.Element;
import com.lowagie.text.pdf.PdfContentByte;

import us.gaaoc.framework.model.Documents;
import us.gaaoc.framework.model.VisualMark;
import us.gaaoc.framework.util.DateUtil;

public class SignDateController {

	public void addSignDate(PdfContentByte over,VisualMark visualMark_signDate, Documents doc,String roleUuid,float x,float y)
	{
		TimeZone tz = TimeZone.getTimeZone("America/New_York");
		GregorianCalendar calendar = new GregorianCalendar(tz);
		String courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
		
		String day = calendar.get(Calendar.DATE) + "";
		String month = (calendar.get(Calendar.MONTH) + 1) + "";
		String year = calendar.get(Calendar.YEAR) + "";
		month = DateUtil.changeMonthFromNumberToWord(month);
		if(doc.getDocumentInstance().getCode() == 1196 || doc.getDocumentInstance().getCode() == 1197 || doc.getDocumentInstance().getCode() == 86005) //complaint petition for ogle
		{
			
			//draw day on X,Y
			//draw month on X+chars*font_width,Y
			//draw year on X+chars*font_width+month_chars*font_width,Y
/*	Commmented on 1/11/2009 over.beginText();
			over.showTextAligned(Element.ALIGN_LEFT, day, x-230, y, 0);
			over.showTextAligned(Element.ALIGN_LEFT, month, x-120, y, 0);
			over.showTextAligned(Element.ALIGN_LEFT, "," + year, x, y, 0);
			over.endText();*/
			over.beginText();
			over.showTextAligned(Element.ALIGN_LEFT, day, x+10, y, 0);
			over.showTextAligned(Element.ALIGN_LEFT, month, x+70, y, 0);
			over.showTextAligned(Element.ALIGN_LEFT, "," + year, x+130, y, 0);
			over.endText();
			
		}else if(doc.getDocumentInstance().getCode() == 1441) //rule nisi for ogle
		{
			//draw day on X,Y
			//draw month on X+chars*font_width,Y
			//draw year on X+chars*font_width+month_chars*font_width,Y
			over.beginText();
			
			over.showTextAligned(Element.ALIGN_LEFT, month, x+10, y, 0);
			over.showTextAligned(Element.ALIGN_LEFT, day, x-60, y, 0);
			over.showTextAligned(Element.ALIGN_LEFT, "," + year, x+100, y, 0);
			over.endText();
		}else{

			over.beginText();
			y -= 10;


			// Convert month date number to name of month
			
            //Edited by Bhawana
			if(courtUuid.equalsIgnoreCase("courtUuid5") || courtUuid.equalsIgnoreCase("courtUuidFranklin") || courtUuid.equalsIgnoreCase("courtUuidHart") ) { //Oglethorpe County
					over.showTextAligned(Element.ALIGN_LEFT, day, x-330, y-18, 0);
			} else {
					over.showTextAligned(Element.ALIGN_LEFT, day, x,
							y + 10, 0);
			}
			if(courtUuid.equalsIgnoreCase("courtUuid3") && roleUuid.equalsIgnoreCase("uuid2")) //clerk
			{
				over.showTextAligned(Element.ALIGN_LEFT, month, x + 56,
						y + 10, 0);
			}else if(courtUuid.equalsIgnoreCase("courtUuid5")  || courtUuid.equalsIgnoreCase("courtUuidFranklin")|| courtUuid.equalsIgnoreCase("courtUuidHart")) { //Oglethorpe County
				over.showTextAligned(Element.ALIGN_LEFT, month, x-220, y-18, 0);}
			else{
				over.showTextAligned(Element.ALIGN_LEFT, month, x + 100,
						y + 10, 0);
			}
			if(courtUuid.equalsIgnoreCase("courtUuid3"))
			{
				over.showTextAligned(Element.ALIGN_LEFT, year, x + 175,
						y + 10, 0);
			}else if(courtUuid.equalsIgnoreCase("courtUuid5")  || courtUuid.equalsIgnoreCase("courtUuidFranklin")|| courtUuid.equalsIgnoreCase("courtUuidHart")) { //Oglethorpe County
				over.showTextAligned(Element.ALIGN_LEFT, year, x - 120, y-18, 0);
			}else{
					over.showTextAligned(Element.ALIGN_LEFT, year, x + 175,
							y + 10, 0);
			}
			over.endText();
		}
	}
		
}
